<template lang="html">
  <div class="main">
    <div class="main-body">
      <div class="title">
        基本热力图
      </div>
      <div class="body">
        <div id="test_chart" class="chart">
        </div>
      </div>
    </div>
    <div class="main-menu">
      <div class="menu">
        <span @click="back">上一个</span>
        <span @click="back">返回</span>
        <span @click="back">下一个</span>
      </div>
    </div>
  </div>
</template>

<script>
import { lazyAMapApiLoaderInstance } from 'vue-amap';
import {heatmapData} from './data';
// let map = {};
export default {
  data () {
    return {
      showamap: false,
      thisRun: [],
      map: null
    };
  },
  methods: {
    back () {
      this.$router.go(-1);
    },
    draw () {
    },
    setMap () {
      var layer = Loca.visualLayer({
        container: this.map,
        type: 'heatmap',
        shape: 'normal'
      });

      var list = [];
      var i = -1;
      var length = heatmapData.length;
      while (++i < length) {
        var item = heatmapData[i];
        list.push({
          coordinate: [item.lng, item.lat],
          count: item.count
        });
      }

      layer.setData(list, {
        lnglat: 'coordinate',
        value: 'count'
      });

      layer.setOptions({
        style: {
          radius: 25,
          opacity: [0, 0.7]
        },
        gradient: {
          0.5: 'blue',
          0.65: 'rgb(117,211,248)',
          0.7: 'rgb(0, 255, 0)',
          0.9: '#ffea00',
          1.0: 'red'
        }
      });
      layer.render();
    }
  },
  mounted () {
    setTimeout(_ => {
      this.showamap = true;
      lazyAMapApiLoaderInstance.load().then(() => {
        this.map = Loca.create('test_chart', {
          features: ['bg', 'road'],
          center: [116.397475, 39.908668],
          zoom: 10
        });
        this.setMap();
      });
    }, 600);
  }
};
</script>

<style lang="css" scoped>
.main {
  background-image: url('../../assets/bg_all_2.png');
  background-repeat: no-repeat;
  background-size: 100% 100%;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  vertical-align: middle;
  justify-content: center;
  align-items: center;
  text-align: center;
  .main-body {
    width: 70%;
    height: 70%;
    box-shadow: 2px 6px 12px 2px rgba(0,0,0,.8);
    border-radius: 4px;
    border: 3px solid #ebeef5;
    background-color: rgba(255,255,255,.95);
    overflow: hidden;
    color: #303133;
    transition: .3s;
    .title {
      position: relative;
      height: 60px;
      line-height: 60px;
      text-align: left;
      margin-left: 20px;
      margin-right: 20px;
    }
    .title::after {
      content: '';
      position: absolute;
      width: 100%;
      height: 3px;
      top: 100%;
      left: 0px;
      overflow: hidden;
      border-top: 1px solid  rgba(150,150,150,.5);
      border-bottom: 1px solid  rgba(255,255,255,1);
      background-color: #eee;
    }
    .body {
      padding: 10px;
      height: 100%;
      width: 100%;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
      .chart {
        width: 100%;
        height: 100%;
      }
    }
  }
  .main-menu {
    width: 70%;
    height: 50px;
    margin-top: 15px;
    position: relative;
    .menu {
      font-size: 20px;
      font-family: '微软雅黑';
      color: rgba(255,255,255,0.5);
      display: flex;
      flex-direction: row;
      vertical-align: middle;
      justify-content: center;
      align-items: center;
      text-align: center;
      height: 100%;
      margin-left: 30%;
      margin-right: 30%;
      span {
        display: block;
        flex: 1;
        cursor: pointer;
      }
      span:hover {
        transition: all .3s;
        font-size: 26px;
      }
    }
    .menu::after {
      content: '';
      position: absolute;
      width: 50%;
      height: 20px;
      top: 100%;
      overflow: hidden;
      background-size:100% 100%;
      background-image: url('../../assets/pic_back_tips.png');
    }
  }
}
</style>
<style media="screen">
.info {
    border: solid 1px silver;
}
div.info-top {
    position: relative;
    background: none repeat scroll 0 0 #F9F9F9;
    border-bottom: 1px solid #CCC;
    border-radius: 5px 5px 0 0;
}
div.info-top div {
    display: inline-block;
    color: #333333;
    font-size: 14px;
    font-weight: bold;
    line-height: 31px;
    padding: 0 10px;
}
div.info-top img {
    position: absolute;
    top: 10px;
    right: 10px;
    transition-duration: 0.25s;
}
div.info-top img:hover {
    box-shadow: 0px 0px 5px #000;
}
div.info-middle {
    font-size: 12px;
    padding: 6px;
    line-height: 20px;
}
div.info-bottom {
    height: 0px;
    width: 100%;
    clear: both;
    text-align: center;
}
div.info-bottom img {
    position: relative;
    z-index: 104;
}
.info-middle img {
    float: left;
    margin-right: 6px;
}
</style>
